package com.guanganren.db.dao.impl;

import java.util.List;


import org.hibernate.classic.Session;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.guanganren.db.dao.UserDao;
import com.guanganren.db.entity.User;

public class UserDaoImpl extends HibernateDaoSupport implements UserDao {

	@Override
	public void add(User u) throws Exception {
		Session session = null;
		try{
			session = (Session)this.getSession();
			session.save(u);
			
		}catch(Exception ex){
			throw new Exception();
		}
		
	}

	@Override
	public void update(User u) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void delete(User u) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public User getById(String pk) {

		User user = this.getHibernateTemplate().get(User.class, pk);
		return user;
	}

	@Override
	public List<User> getExistUser(String key, String value) {
		List<User> list=null;
		try{
			String queryString = "from com.guanganren.db.entity.User where "+key+"=?";
			System.out.println(queryString);
			list = this.getHibernateTemplate().find(queryString,value);
		}catch(Exception ex){
			ex.printStackTrace();
		}
		
		return list;
	}

}
